package com.cssw.fyzb.tps.api.im;


import cn.hutool.http.server.HttpServerRequest;
import cn.hutool.http.server.HttpServerResponse;
import com.cssw.fyzb.tps.service.im.MessageService;
import com.cssw.fyzb.tps.service.im.common.ImHttpComm;
import com.ydn.appserver.Action;
import com.ydn.appserver.Request;
import com.ydn.appserver.Response;
import com.ydn.appserver.annotations.Function;
import com.ydn.appserver.annotations.Parameter;
import com.ydn.appserver.annotations.Type;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @Author Jian Qin.
 */
@Function(description = "设置单聊消息已读", parameters = {
        @Parameter(name = "report_Account", type = Type.String, description = "进行消息已读的用户 UserId"),
        @Parameter(name = "peer_Account", type = Type.String, description = "进行消息已读的单聊会话的另一方用户 UserId"),
})
@Component
public class SetMsgRead implements Action {
    @Autowired
    private MessageService messageService;

    @Override
    public Response execute(Request request) throws Exception {
        ImHttpComm.ImResult result = messageService.setMsgRead(
                request.getString("report_Account"),
                request.getString("peer_Account"));

        if(result.getErrorCode() == 0){
            return Response.success();
        }else{
            return Response.fail(result.getErrorInfo(), result.getErrorCode());
        }
    }
}
